package com.yanqu.road.server.cmd.player;

import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.pb.activity.OldPlayerReturnProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ：zfr
 * @date ：2021/12/7 18:25
 */
@Cmd(code = CrossProtocol.C_CROSS_GET_OTHER_RETURN_ROLE_INFO_RESP, desc = "跨服获取其他角色信息响应")
public class CrossGetReturnRoleInfoRespCmd extends CrossCommand {
    private long oriServerId;
    private long oriPlayerId;
    private List<OldPlayerReturnProto.RoleUserInfoTemp> userInfoList = new ArrayList<>();
    private long canReturnTime;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        OldPlayerReturnProto.GetOtherReturnRoleInfoRespToCrossMsg msg = OldPlayerReturnProto.GetOtherReturnRoleInfoRespToCrossMsg.parseFrom(packet.getBytes());
        oriServerId = msg.getOriServerId();
        oriPlayerId = msg.getOriPlayerId();
        userInfoList = msg.getUserInfoList();
        canReturnTime = msg.getCanReturnTime();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        OldPlayerReturnProto.GetOtherReturnInfoRespToServerMsg.Builder respMsg = OldPlayerReturnProto.GetOtherReturnInfoRespToServerMsg.newBuilder();
        respMsg.setBindServerId(serverId);
        for (OldPlayerReturnProto.RoleUserInfoTemp userInfoBuilder : userInfoList) {
            respMsg.addUserInfo(userInfoBuilder);
        }
        respMsg.setCanReturnTime(canReturnTime);
        YanQuMessage message = YanQuMessageUtils.buildMessage(GameProtocol.S_CROSS_GET_RETURN_ROLE_INFO_RESP, respMsg);
        MessageHelper.sendPacket(oriServerId, oriPlayerId, message);
    }

    @Override
    public void sendData() {

    }
}
